package com.imooc.articles_mongodb_project.controller;

import com.imooc.articles_mongodb_project.common.Result;
import com.imooc.articles_mongodb_project.common.validator.SaveValidator;
import com.imooc.articles_mongodb_project.dto.LikesDTO;
import com.imooc.articles_mongodb_project.service.ILikesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "点赞数据的管理接口")
@RestController
@RequestMapping("/likes")
public class LikesController {
    @Autowired
    private ILikesService likesService;

    @ApiOperation(value = "保存点赞")
    @RequestMapping("/save")
    public Result save(@RequestBody @Validated(SaveValidator.class) LikesDTO likesDTO) {
        return likesService.save(likesDTO);
    }

    @ApiOperation(value = "获取点赞数")
    @RequestMapping("/{articleId}")
    public Result getLikeNums(@PathVariable("articleId") String articleId) {
        return likesService.getLikeNums(articleId);
    }


}
